import request from '@/utils/request'

// 接口类型定义
export interface LoginData {
  username: string
  password: string
}

export interface RegisterData {
  username: string
  password: string
  nickname?: string
  email?: string
  mobile?: string
}

export interface LoginResponse {
  data: {
    token: string
  }
}

export interface UserProfile {
  id: string
  username: string
  name: string | null
  avatar: string
  createdAt: string
  updatedAt: string
}

export interface UserProfileResponse {
  data: UserProfile
}

// 注册接口
export const registerAPI = (data: RegisterData) => {
  return request.post('/h5/user/register', data)
}

// 登录接口
export const loginAPI = (data: LoginData): Promise<LoginResponse> => {
  return request.post('/h5/user/login', data)
}

// 获取用户信息
export const getUserProfileAPI = (): Promise<UserProfileResponse> => {
  return request.get('/h5/user/currentUser')
}

// 退出登录接口
export const logoutAPI = () => {
  return request.get('/h5/user/logout')
}

